<% if environments.any? -%>
managed_servers = VagrantPlugins::Orchestrate::Plugin.load_servers_for_branch
<% else -%>
managed_servers = %w( <% servers.each do |s| -%><%= s %> <% end -%>)
<% end -%>

<% if plugins.any? -%>
required_plugins = %w( <% plugins.each do |p| -%><%= p %> <% end -%>)
required_plugins.each do |plugin|
  system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
end
<% end %>
Vagrant.configure("2") do |config|
  # This disables up, provision, reload, and destroy for managed servers. Use
  # `vagrant orchestrate push` to communicate with managed servers.
  config.orchestrate.filter_managed_commands = true
  <% if creds_prompt -%>
  config.orchestrate.credentials.prompt = true
  <% end -%>
  <% if creds_file_path -%>
  config.orchestrate.credentials.file_path = "<%= creds_file_path%>"
  <% end -%>

  <% if provisioners.include? "shell" -%>
  <% shell_paths.each do |path| -%>
  config.vm.provision "shell", path: "<%= path %>"
  <% end -%>
  <% if shell_inline -%>
  config.vm.provision "shell", inline: "<%= shell_inline %>"
  <% end -%>
  <% end -%>
  <% if provisioners.include? "puppet" -%>
  <% if puppet_librarian_puppet -%>
  config.librarian_puppet.placeholder_filename = ".gitignore"
  <% end -%>
  config.vm.provision "puppet" do |puppet|
    <% if puppet_librarian_puppet -%>
    puppet.module_path = 'puppet/modules'
    <% end -%>
    <% if puppet_hiera -%>
    puppet.hiera_config_path = 'puppet/hiera.yaml'
    <% end -%>
    puppet.manifests_path = 'puppet/manifests'
  end
  <% end -%>
  <% if communicator == "ssh" -%>
  config.ssh.username = "<%= ssh_username %>"
  <% if ssh_password -%>
  config.ssh.password = "<%= ssh_password %>"
  <% end -%>
  <% if ssh_private_key_path -%>
  config.ssh.private_key_path = "<%= ssh_private_key_path %>"
  <% end -%>
  <% end -%>
  <% if communicator == "winrm" -%>
  config.vm.communicator = "<%= communicator %>"
  config.winrm.username = "<%= winrm_username %>"
  config.winrm.password = "<%= winrm_password %>"
  <% end -%>

  config.vm.define "local", primary: true do |local|
    local.vm.box = "ubuntu/trusty64"
  end

  managed_servers.each do |instance|
    config.vm.define instance, autostart: false do |box|
      box.vm.box = "managed-server-dummy"
      box.vm.box_url = "./dummy.box"
      box.vm.provider :managed do |provider|
        provider.server = instance
      end
      <% if communicator == "winrm" =%>
      box.winrm.transport = :sspinegotiate
      <% end -%>
    end
  end
end
